#!/usr/bin/env bash

# Note: the output of this script is normally found at
#  /var/log/cont/selenium-node-chrome-stderr.log

# Debian/Ubuntu seems to not respect --lang, it instead needs to be a LANGUAGE environment var
# See: https://stackoverflow.com/a/41893197/359999
for var in "$@"; do
   if [[ $var == --lang=* ]]; then
      export LANGUAGE=${var//--lang=}
   fi
done

exec /opt/google/chrome/google-chrome-base "$@" ${CHROME_ARGS} ${CHROME_ADDITIONAL_ARGS}

# See: On How To Turn Chrome or Firefox Into A Single-Site Browser
# Google Chrome users can make use of the --host-rules parameter to block all domain connections except the ones they whitelist. The general parameter looks like this:
#
#     --host-rules="MAP * 127.0.0.1, EXCLUDE *.ghacks.net"
#
# This redirects all connection attempts to localhost, except for connections to the ghacks.net site or one of its subdomains.
# You can also add multiple inclusions in the following way:
#
#     --host-rules="MAP * 127.0.0.1, EXCLUDE *.ghacks.net","MAP * 127.0.0.1, EXCLUDE *.microsoft.com"
# https://github.com/electron/electron/blob/master/docs/api/chrome-command-line-switches.md#--host-rulesrules
#
# @outerpasta idea:
#
# if [ "${THE_DOCKER_HOST_IP}" != "" ]; then
#   exec /opt/google/chrome/google-chrome-base "$@" ${CHROME_ARGS} --host-rules="MAP localhost ${THE_DOCKER_HOST_IP}"
# else
#   exec /opt/google/chrome/google-chrome-base "$@" ${CHROME_ARGS}
# fi
